<?php
require_once dirname(__FILE__)."/base_model.php";
class options extends base_model {

	const OPTIONS_TABLE = "table_options";

	public function __construct() {
		parent::__construct();
	}

	//表单选项
	public function getOptionsByType($option_type, $option_pid='') {
		$this->db->select('option_id, option_name');
		$this->db->where('option_type', $option_type);
		if (isset($option_pid) && !empty($option_pid))
			$this->db->where('option_pid', $option_pid);
		$this->db->from(self::OPTIONS_TABLE);
		return $this->db->get()->result_array();
	}

	//表单选项
	public function getOptionsWhereInTypes(array $option_types) {
		$this->db->select('option_id, option_name, option_type');
		$this->db->where_in('option_type', $option_types);
		$this->db->from(self::OPTIONS_TABLE);
		return $this->db->get()->result_array();
	}

	/**
	 * 获取option
	 * @param string $type 为空，取全部配置项
	 * @param int $code 为空，取全部（当前类型）
	 * @return array
	 */
	public function getTableOptions($type=null, $code=null)
	{
	    $this->db->from(self::OPTIONS_TABLE);
	    if ($type) {
	    	$this->db->where("option_type", $type);
	    	if ($code) {
	    		$this->db->where("option_id", $code);
	    	}
	    }
	    $this->db->orderby("option_type, option_id");
	    return $this->db->get()->result_array();

	}
}